package com.wanxi.servlet.lawyer;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.dto.ResultDto;
import com.wanxi.model.LawyerModel;
import com.wanxi.service.Impl.LawyerServiceImpl;
import com.wanxi.service.LawyerService;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Li
 * @Date 2023/5/4 21:36
 */
@WebServlet("/back/DeleteLawyer")
public class LawyerDeleteServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //获取前端数据
        String id = req.getParameter("id");
        //封装model
        LawyerModel lawyerModel = LawyerModel.builder()
                .id(Tool.strToInt(id))
                .build();
        //service层
        LawyerService lawyerService =new LawyerServiceImpl();
        ResultDto resultDto = lawyerService.delete(lawyerModel);
        //返回给前端数据
        resp.getWriter().println(JSONObject.toJSONString(resultDto));
    }
}
